package Function;

import VWorldGameStudio.events.CaseEvent;
import VWorldGameStudio.events.MapHiddenEvent;
import com.google.gson.Gson;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import utils.FCDataSingles;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class BuildFCMapHideEventMain {
    private static final String ITEM_FILE = "./重装机兵V-数据-怪物.xls";
    private Gson gson = new Gson();
    Sheet sheet;

    public static void main(String[] args) {
        BuildFCMapHideEventMain main = new BuildFCMapHideEventMain();
        main.init();
    }


    private void init(){
        FCEventLibrary fcEventLibrary = new FCEventLibrary();
        fcEventLibrary.loadEventData();

        try {
            int ids = 1;
            File file = new File(ITEM_FILE);
            // 创建输入流，读取Excel
            InputStream is = new FileInputStream(file.getAbsolutePath());
            // jxl提供的Workbook类
            Workbook wb = Workbook.getWorkbook(is);
            sheet = wb.getSheet(5);

            for (int i = 1; i < sheet.getRows(); i++) {
                Cell[] cells = sheet.getRow(i);
                if (cells != null && cells.length > 4) {
                    if (cells[2] == null || cells[2].getContents().isEmpty()) {
                        continue;
                    }
                    String caseEventNam = cells[2].getContents().trim();
                    int money = 0;
                    if(cells[3] != null && !cells[3].getContents().isEmpty()){
                        money = Integer.parseInt(cells[3].getContents().trim());
                    }
                    MapHiddenEvent hiddenEvent = new MapHiddenEvent("mapHiddenItem", caseEventNam);
                    hiddenEvent.setMoney(money);
                    String item = "null";
                    if(cells[4] != null && !cells[4].getContents().isEmpty()){
                        item = cells[4].getContents().trim();
                    }
                    hiddenEvent.setHiddenitemId(item);

                    FCDataSingles.getWriter().writeEventData(hiddenEvent);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
